package com.ng.framework.view.desktop.table;

import java.awt.Color;

import javax.swing.table.DefaultTableModel;

public class NGTableModel extends DefaultTableModel {

	private static final long serialVersionUID = -9189768070620063128L;

	private NGCellAttributes cellAttributes;

	public NGTableModel(Object[] columnNames, int numRows) {
		super(columnNames, numRows);
		
		this.cellAttributes = new NGCellAttributes(numRows, columnNames.length);
	}

	public void addColumn(Object columnName) {
		this.cellAttributes.addColumn();
		
		super.addColumn(columnName);
	}

	public void addRow(Object[] rowData) {
		cellAttributes.addRow();
		
		if (rowData == null) {
			rowData = new Object[this.getColumnCount()];
		}
		
		super.addRow(rowData);
	}

	public void insertRow(int row, Object[] rowData) {
		cellAttributes.insertRow(row);
		
		if (rowData == null) {
			rowData = new Object[this.getColumnCount()];
		}

		super.insertRow(row, rowData);
	}
	
	public NGCellAttributes getCellAttributes() {
		return cellAttributes;
	}

	@Override
	public boolean isCellEditable(int row, int column) {
		return cellAttributes.isEditable(row, column);
	}
		
	public void setCellEditable(int row, int column, boolean editable) {
		cellAttributes.setEditable(row, column, editable);
	}
	
	public void setCellForeground(int row, int column, Color foreground) {
		cellAttributes.setCellForeground(row, column, foreground);
	}
	
	public void setCellBackground(int row, int column, Color background) {
		cellAttributes.setCellBackground(row, column, background);
	}
	
	public Color getCellBackground(int row, int column) {
		return cellAttributes.getCellBackground(row, column);
	}
	
	public void setCellAlignment(int row, int column, Integer alignment) {
		cellAttributes.setCellAlignment(row, column, alignment);
	}
	
	public int getCellAlignment(int row, int column) {
		return cellAttributes.getCellAlignment(row, column);
	}

	public void setFractionColumn(int column, boolean fraction) {
		cellAttributes.setFractionColumn(column, fraction);
	}
	
	public boolean isFractionColumn(int column) {
		return cellAttributes.isFractionColumn(column);
	}
}
